package org.sg20.utils;

@Deprecated
public class LpaDot extends Dot<int[]> {


    /**
     * 指定点的名字和可能取值的标签总数
     * 初始时所有标签取值概率都为0
     */
    public LpaDot(String name, int labelnum) {
        super(name);
        this.val = new int[labelnum]; //int数组默认值为0
    }

    /**
     * 指定指定点的名字和可能取值的标签总数,和该点的初始标签
     * 则初始标签概率为1,其它为0
     */
    public LpaDot(String name, int labelNum, int label) {
        super(name);
        this.val = new int[labelNum]; //int数组默认值为0
        this.val[label] = 1;
    }

    public void addLabelProbability(int label, int probability) {
        this.val[label] += probability;
    }

    /**
     * @return name, [pr0, pr1, ...]"
     */
    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder(name);
        sb.append(",[").append(this.val[0]);
        for (int i = 1; i < this.val.length; i++) {
            sb.append(",").append(this.val[1]);
        }
        sb.append("]");
        return sb.toString();
    }

    /**
     * 获取改点的标签
     *
     * @return 以概率最大的作为标签
     */
    public int getLabel() {
        int maxIndex = 0;
        int maxProbability = 0;
        for (int i = 0; i < this.val.length; i++) {
            if (this.val[i] > maxProbability) {
                maxProbability = this.val[i];
                maxIndex = i;
            }
        }
        return maxIndex;
    }
}
